//
// Ephi - simulation of magnetic fields and particles
// Copyright (C) 2007 Indrek Mandre <indrek(at)mare.ee>
// For more information please see http://www.mare.ee/indrek/ephi/
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "ephi.hpp"

// compare bfield with single-wire versus real thick coil simulation

#define RADIUS 0.2
#define WIDTH 0.1
#define I 1.0
#define OFFSET 0

int main (int argc, char *argv[])
{
  Statics cstat;
  ElectroDynamics cdyn(cstat);
  ShapedCoilFactory(1).make (cstat, vect3d(0, 0, 0), vect3d(0, 0, 1), RADIUS, WIDTH/2, I, 0);

  for ( int k = 1; k <= 32; k++ )
    {
      Statics statics;
      ElectroDynamics dyn(statics);
      ShapedCoilFactory cs(k);
      cs.set_circle();
      cs.make (statics, vect3d(0, 0, 0), vect3d(0, 0, 1), RADIUS, WIDTH/2, I, 0);
      vect3d bf;
      dyn.getBField (vect3d(0, 0, OFFSET), bf);
      vect3d cbf;
      cdyn.getBField (vect3d(0, 0, OFFSET), cbf);
      printf ("%d: %.6f%%\n", k, prec2double(100*fabs(bf.length() - cbf.length())/cbf.length()));

#if 0
      FILE *fout = fopen ("polywell.inc", "w");
      fprintf (fout, "%s", statics.get_povray_script().c_str());
      fclose (fout);
#endif
    }

  return 0;
}

